/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.eagleeyes.hoverbuttons.jogl;

import java.util.LinkedList;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import org.eagleeyes.hoverbuttons.EEMouseMotionListener;

/**
 * A Panel using GLEEButtons for an Eagle Eyes/JOGL application.  Implementing classes should override
 * all the methods of GLEventListener.  The display(GLAutoDrawable) method should call super.display(GLAutoDrawable)
 * in the proper context: a 2D setup.
 * @author Jesse Bahr
 */
public abstract class GLEEPanel extends GLCanvas implements GLEventListener{
  private LinkedList<GLEEButton> buttons;
  private EEMouseMotionListener mouseListener;
  
  private void init(){
    buttons = new LinkedList<GLEEButton>();
    mouseListener = new EEMouseMotionListener();
    addMouseMotionListener(mouseListener);
    addGLEventListener(this);
  }
  
  public GLEEPanel(){
    init();
  }
  
  public GLEEPanel(GLCapabilities cap){
    super(cap);
    init();
  }
    
  public void addButton(GLEEButton b){
    mouseListener.add(b);
    buttons.add(b);
  }
  
  public void removeButton(GLEEButton b){
    mouseListener.remove(b);
    buttons.remove(b);
  }
  
  public void removeAllButtons(){
    buttons.clear();
    mouseListener.removeAll();
  }
  
  public void display(GLAutoDrawable glad) {
    GL gl = glad.getGL();
    for (GLEEButton button: buttons){
      button.draw(gl);
    }
  }
}
